package com.example.bookdemo.dao;

import com.example.bookdemo.model.bookInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookInfoMapper {
    //获取图书信息
    @Select("select * from book_info where status!=0")
    List<bookInfo> selectInfo();

    @Insert("insert into book_info(book_name,author,count,price,publish,`status`)" +
            "values (#{bookInfo.bookName},#{bookInfo.author},#{bookInfo.count},#{bookInfo.price},#{bookInfo.publish},#{bookInfo.status})")
    Integer insertBook(@Param("bookInfo") bookInfo bookInfo);

    //获取记录数量
    @Select("select count(1) from book_info where status!=0")
    Integer count();

    //返回对应页数的数据

    @Select("select * from book_info where status!=0 ORDER BY id ASC LIMIT #{offset},#{limit}")
    List<bookInfo> getBookByPage(@Param("offset")Integer offset,@Param("limit")Integer limit);

    //查询返回对应id的数据
    @Select("select * from book_info where id=#{id}")
    bookInfo selectById(@Param("id")Integer id);

    //修改,前端返回了哪些修改信息向数据库进行对应请求,因为不确定修改的数据数量,所以需要使用xml
    Integer updateBookById(bookInfo bookInfo);


    //删除,选择id,进行修改
    @Update("update book_info set status = 0 where id = #{id}")
    Integer deleteById(@Param("id")Integer id);


    //批量删除,通过获取部分id来进行修改
    Integer batchDelete(List<Integer> ids);
}
